#!/bin/bash

# Turritopsis maxN Dynamic Reconfiguration Examples
# This script demonstrates the flexible maxN feature

echo "=== Turritopsis maxN Dynamic Reconfiguration Examples ==="
echo

# Change to the correct directory
cd "$(dirname "$0")/.."

echo "1. Basic maxN Test: N=4 to maxN=15 (fixed L=0)"
echo "   Command: ./turritopsis_full --epochs 10 --r 2 --n 4 --f 1 --maxn 15 --dyn-l 0 --acs-addr \"\""
echo "   Expected: Scale up to N=15, then stay at maxN"
echo

echo "2. Complex maxN Test: N=5 to maxN=20 (random L, seed=999)"
echo "   Command: ./turritopsis_full --epochs 15 --r 3 --n 5 --f 1 --maxn 20 --dyn-l-max 3 --dyn-seed 999 --acs-addr \"\""
echo "   Expected: Scale up to N=20, then fluctuate (30% down, 40% stay, 30% fluctuate)"
echo

echo "3. Large Scale Test: N=8 to maxN=30 (random L, seed=456)"
echo "   Command: ./turritopsis_full --epochs 20 --r 4 --n 8 --f 1 --maxn 30 --dyn-l-max 2 --dyn-seed 456 --acs-addr \"\""
echo "   Expected: Scale up to N=30, then dynamic behavior"
echo

echo "4. Small Scale Test: N=3 to maxN=10 (fixed L=1)"
echo "   Command: ./turritopsis_full --epochs 12 --r 2 --n 3 --f 1 --maxn 10 --dyn-l 1 --acs-addr \"\""
echo "   Expected: Scale up to N=10, then stay at maxN"
echo

echo "5. High Frequency Test: N=6 to maxN=25 (random L, R=1)"
echo "   Command: ./turritopsis_full --epochs 18 --r 1 --n 6 --f 1 --maxn 25 --dyn-l-max 3 --dyn-seed 789 --acs-addr \"\""
echo "   Expected: Scale up to N=25, ADKR every epoch"
echo

echo "=== Key Features of maxN ==="
echo "• Flexible scaling: May reach maxN but not necessarily at the end"
echo "• Dynamic behavior: 30% chance to scale down, 40% to stay, 30% to fluctuate"
echo "• Auto F calculation: F = (N-1)/3"
echo "• Random L generation: 0 to dyn-l-max, satisfying safety inequality"
echo "• Safety guarantee: n >= 3f + 2l + 1 always maintained"
echo

echo "=== Usage Examples ==="
echo "# Basic usage"
echo "./turritopsis_full --epochs 20 --r 5 --n 4 --f 1 --maxn 15 --dyn-l 0"
echo
echo "# With random L"
echo "./turritopsis_full --epochs 25 --r 4 --n 6 --f 1 --maxn 20 --dyn-l-max 2 --dyn-seed 789"
echo
echo "# High frequency ADKR"
echo "./turritopsis_full --epochs 30 --r 1 --n 8 --f 1 --maxn 25 --dyn-l 1"
echo

echo "=== Comparison with Other Dynamic Modes ==="
echo "• dyn-preset: Fixed patterns (scale-up, scale-down, mixed, wave)"
echo "• dyn-range: Linear transition from startN to endN"
echo "• maxn: Flexible scaling with dynamic behavior after reaching maxN"
echo "• dyn-file: Custom plans from JSON/CSV files"
echo

echo "=== Safety Inequality Verification ==="
echo "All generated N, F, L combinations satisfy: n >= 3f + 2l + 1"
echo "This ensures the mixed fault tolerance model is maintained."
echo

echo "=== Performance Notes ==="
echo "• Phase 1 (60% of epochs): Linear scale up from startN to maxN"
echo "• Phase 2 (40% of epochs): Dynamic behavior (down/stay/fluctuate)"
echo "• Random seed controls L generation and Phase 2 behavior"
echo "• ADKR execution follows R interval regardless of N changes"
echo

echo "Ready to run maxN tests! Choose an example above or create your own."




